package com.bicon.botu.core.base.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by L on 2017/2/27.
 * 正则匹配工具类
 */
public class MatcherUtil {


    /**
     * 正则匹配邮箱地址
     * @param email
     * @return
     */
    public static boolean matcherEmail(String email){
        //邮箱地址进行正则
        String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(email);
        boolean isMatched = matcher.matches();
        return isMatched;
    }

    /**
     * 正则匹配手机号
     * @param phone
     * @return
     */
    public static boolean matcherPhone(String phone){
        //邮箱地址进行正则
        String check = "^(1[3,4,5,7,8])\\d{9}$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(phone);
        boolean isMatched = matcher.matches();
        return isMatched;
    }

    /**
     * 正则匹配中文，英文字母
     * @param str
     * @return
     */
    public static boolean matcherChineseAndEnglish(String str){
        //邮箱地址进行正则
        String check = "^[\\u4e00-\\u9fa5_a-zA-Z0-9_]{1,10}";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(str);
        boolean isMatched = matcher.matches();
        return isMatched;
    }

    /**
     * 正则匹配身份证
     * @param str
     * @return
     */
    public static boolean matcherIdCard(String str){
        //邮箱地址进行正则
        String check = "^(^\\d{15}$)|(^\\d{17}(\\d|X)$)";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(str);
        boolean isMatched = matcher.matches();
        return isMatched;
    }

}
